﻿@{
    ViewBag.Title = "仓库报表";
    Layout = "~/Views/Shared/_ReportIndex.cshtml";
}
<script>
    $(function () {
        GetGrid();
    })
    function GetGrid() {
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../ReportManage/ReportDemo/GetStoreJson",
            datatype: "json",
            height: $(window).height() - 258.5,
            autowidth: true,
            colModel: [
                { name: "invNo", label: "商品编号", width: 100, align: "left" },
                { name: "invName", label: "商品名称", width: 200, align: "left" },
                { name: "date", label: "单据日期", width: 100, align: "center" },
                { name: "billNo", label: "单据单号", width: 100, align: "center" },
                { name: "billType", label: "业务类别", width: 100 },
                { name: "buName", label: "往来单位", width: 100 },
                { name: "location", label: "仓库", width: 80 },
                { name: "inqty", label: "入库数量", width: 100, align: "left" },
                { name: "inunitCost", label: "单位成本", width: 100, align: "left" },
                { name: "incost", label: "成本", width: 100, align: "left" },
                { name: "outqty", label: "出库数量", width: 100, align: "left" },
                { name: "outunitCost", label: "单位成本", width: 100, align: "left" },
                { name: "outcost", label: "成本", width: 100, align: "left" },
                { name: "totalqty", label: "结存数量", width: 100, align: "left" },
                { name: "totalunitCost", label: "单位成本", width: 100, align: "left" },
                { name: "totalcost", label: "成本", width: 100, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            footerrow: true,
            gridComplete: function () {
                //合计
                $(this).footerData("set", {
                    "location": "合计：",
                    "qty": "<span id='TotalQty'>0.00</span>",
                    "amount": "<span id='TotalAmount'>0.00</span>",
                });
                $('table.ui-jqgrid-ftable td[aria-describedby="gridTable_location"]').prevUntil().css("border-right-color", "#fff");
            }
        });
        //表头合并
        $gridTable.jqGrid('setGroupHeaders', {
            useColSpanStyle: true,
            groupHeaders: [
              { startColumnName: 'inqty', numberOfColumns: 3, titleText: '入库' },
              { startColumnName: 'outqty', numberOfColumns: 3, titleText: '出库' },
              { startColumnName: 'totalqty', numberOfColumns: 3, titleText: '结存' }
            ]
        });
        //点击时间范围（今天、近7天、近一个月、近三个月）
        $("#time_horizon a.btn-default").click(function () {
            $("#time_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            switch ($(this).attr('data-value')) {
                case "1"://今天
                    $("#StartTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "2"://近7天
                    $("#StartTime").val("@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "3"://近一个月
                    $("#StartTime").val("@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "4"://近三个月
                    $("#StartTime").val("@DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                default:
                    break;
            }
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //打印
    function btn_print() {
        $("#gridPanel").printTable();
    }
    //导出
    function btn_export() {
        dialogOpen({
            id: "ExcelIExportDialog",
            title: '导出仓库报表',
            url: '/Utility/ExcelExportForm?gridId=gridTable',
            width: "500px",
            height: "380px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }, btn: ['导出Excel', '关闭']
        });
    }
</script>
<div class="ui-report">
    <div class="titlePanel">
        <div class="title-search">
            <table>
                <tr>
                    <td>查询条件</td>
                    <td style="padding-left: 10px;">
                        <div class="ui-filter" style="width: 200px;">
                            <div class="ui-filter-text">
                                <strong id="SelectedStartTime">@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.ToString("yyyy-MM-dd")</strong>
                            </div>
                            <div class="ui-filter-list" style="width: 350px;">
                                <table class="form" id="filter-form">
                                    <tr>
                                        <th class="formTitle">单据日期：</th>
                                        <td class="formValue">
                                            <input id="Category" type="hidden" value="1" />
                                            <div style="float: left; width: 45%;">
                                                <input id="StartTime" readonly type="text" value="@LeaRun.Util.Time.GetDate(-7)" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                            </div>
                                            <div style="float: left; width: 10%; text-align: center;">至</div>
                                            <div style="float: left; width: 45%;">
                                                <input id="EndTime" readonly type="text" value="@LeaRun.Util.Time.GetToday()" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="formTitle">单据编号：</td>
                                        <td class="formValue">
                                            <input id="OrderCode" type="text" class="form-control">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="formTitle">商品编号：</td>
                                        <td class="formValue">
                                            <input id="GoodsCode" type="text" class="form-control">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="formTitle">商品名称：</td>
                                        <td class="formValue">
                                            <input id="GoodsName" type="text" class="form-control">
                                        </td>
                                    </tr>
                                </table>
                                <div class="ui-filter-list-bottom">
                                    <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                    <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td style="padding-left: 10px;">
                        <div id="time_horizon" class="btn-group">
                            <a class="btn btn-default" data-value="1">今天</a>
                            <a class="btn btn-default active" data-value="2">近7天</a>
                            <a class="btn btn-default" data-value="3">近1个月</a>
                            <a class="btn btn-default" data-value="4">近3个月</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="toolbar">
            <div class="btn-group">
                <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                <a id="lr-print" class="btn btn-default" onclick="btn_print()"><i class="fa fa-print"></i>&nbsp;打印</a>
                <a id="lr-export" class="btn btn-default" onclick="btn_export()"><i class="fa fa-sign-out"></i>&nbsp;导出</a>
            </div>
            <script>$('.toolbar').authorizeButton()</script>
        </div>
    </div>
    <div class="gridPanel" id="gridPanel">
        <div class="printArea">
            <div class="grid-title">商品收发明细表</div>
            <div class="grid-subtitle">日期: 2011-03-05 至 2016-03-28</div>
            <table id="gridTable"></table>
        </div>
    </div>
</div>
